package com.haima.ziliao.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haima.ziliao.domain.PKevideos;
import com.haima.ziliao.service.IPKevideosService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PVideoke;
import com.haima.ziliao.service.IPVideokeService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 视频课程Controller
 * 
 * @author hima
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/ziliao/videoke")
public class PVideokeController extends BaseController
{
    @Autowired
    private IPVideokeService pVideokeService;
    @Autowired
    private IPKevideosService kevideosService;

    /**
     * 查询视频课程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PVideoke pVideoke)
    {
        startPage();
        List<PVideoke> list = pVideokeService.selectPVideokeList(pVideoke);
        return getDataTable(list);
    }

    @GetMapping("/listMaps")
    public TableDataInfo listAllMaps(PVideoke pVideoke)
    {
        startPage();
        List<Map<String,Object>> list = pVideokeService.listAllMaps(pVideoke);
        return getDataTable(list);
    }
    @GetMapping("/detailData")
    public AjaxResult detailData(PVideoke pVideoke)
    {
        Map<String,Object> data = pVideokeService.getMap(new QueryWrapper<PVideoke>().eq("id",pVideoke.getId()));
        PKevideos pk = new PKevideos();
        pk.setGid(pVideoke.getId());
        List<PKevideos> kes = kevideosService.selectPKevideosList(pk);
        data.put("kcs",kes);
        return AjaxResult.success(data);
    }

    /**
     * 导出视频课程列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:videoke:export')")
    @Log(title = "视频课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PVideoke pVideoke)
    {
        List<PVideoke> list = pVideokeService.selectPVideokeList(pVideoke);
        ExcelUtil<PVideoke> util = new ExcelUtil<PVideoke>(PVideoke.class);
        util.exportExcel(response, list, "视频课程数据");
    }

    /**
     * 获取视频课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:videoke:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pVideokeService.selectPVideokeById(id));
    }

    /**
     * 新增视频课程
     */
    @PreAuthorize("@ss.hasPermi('ziliao:videoke:add')")
    @Log(title = "视频课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PVideoke pVideoke)
    {
        return toAjax(pVideokeService.insertPVideoke(pVideoke));
    }

    /**
     * 修改视频课程
     */
    @PreAuthorize("@ss.hasPermi('ziliao:videoke:edit')")
    @Log(title = "视频课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PVideoke pVideoke)
    {
        return toAjax(pVideokeService.updatePVideoke(pVideoke));
    }

    /**
     * 删除视频课程
     */
    @PreAuthorize("@ss.hasPermi('ziliao:videoke:remove')")
    @Log(title = "视频课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pVideokeService.deletePVideokeByIds(ids));
    }
}
